import 'package:earclean/app/modules/table/controllers/table_controller.dart';
import 'package:earclean/app/request/request_main.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:earclean/app/util/common_utils.dart';
import 'package:earclean/app/util/string_util.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';

class MineController extends GetxController {
   List topdataList = [
    {
      'name': "订单",
      'img': "assets/images/订单@2x.png",
    },
    {
      'name': "钱包",
      'img': "assets/images/钱包@2x.png",
    },
    
  ];
  List dataList = [
    {
      'name': "客服",
      'img': "assets/images/客服热线@2x.png",
    },
    {
      'name': "个人资料",
      'img': "assets/images/257用户资料@2x.png",
    },
    {
      'name': "退出登录",
      'img': "assets/images/退出登录.png",
    },
    {
      'name': "注销用户",
      'img': "assets/images/注销@2x.png",
    },
    {
      'name': "隐私政策",
      'img': "assets/images/隐私@2x.png",
    }
  ];
  final mobile = ''.obs;

  loadData() {
    mobile.value = phoneNumberStr(box.read('mobile'));
  }

  // 去订单
  goOrder() {
    Get.toNamed(Routes.ORDER_LIST);
  }

  // 去客服
  gokefu() {
    Get.toNamed(Routes.GOKEFU);
  }

  // 去个人资料
  goUseInfo() {
    Get.toNamed(Routes.USER_INFO);
  }

  // 退出
  goExit() {
    MshowDialog('是否要退出登录吗？').then((value) async {
      if (value == 1) {
        EasyLoading.show(status: '退出中...');
        Map? m = await RequestMain.postUrl({},
            turl: 'https://fjbamz.jiliol.net/sign/?a=index');
        if (m.isNotEmpty && m['code'].toString() == "200") {
          await box.remove('key');
          await box.remove('kefu');
          await box.remove('tab');
          await box.remove('oneKey');
          await box.remove('mobile');

          // Get.until((route) => route.settings.name == Routes.TABLE);
          // Get.find<TableController>().changePage(0);
          // Get.find<TableController>().loadSet();
          EasyLoading.showToast('退出成功');
          Get.offAndToNamed(Routes.LOGIN);
        } else {
          EasyLoading.dismiss();
        }
      }
    });
  }

  //注销
  goLogout() {
    Get.toNamed(Routes.ZHUXIAO);
  }

  // 隐私政策
  goWeb() {
    Get.toNamed(Routes.WEB, arguments: {
      "title": '隐私政策',
      "url": 'https://iamz.jiliol.net/LegalDocuments/PrivacyPolicy.html',
    });
  }

  clickIten(index) {
    if (index == 0) {
      dynamic key = box.read("key");
      if (null == key) {
        Get.offAndToNamed(Routes.LOGIN);
      } else {
        gokefu();
      }
    } else if (index == 1) {
      dynamic key = box.read("key");
      if (null == key) {
        Get.offAndToNamed(Routes.LOGIN);
      } else {
        goUseInfo();
      }
    } else if (index == 2) {
      dynamic key = box.read("key");
      if (null == key) {
        Get.offAndToNamed(Routes.LOGIN);
      } else {
        goExit();
      }
    } else if (index == 3) {
      dynamic key = box.read("key");
      if (null == key) {
        Get.offAndToNamed(Routes.LOGIN);
      } else {
        goLogout();
      }
    } else if (index == 4) {
      goWeb();
    }
  }

  @override
  void onInit() {
    mobile.value = box.read('mobile') ?? "";
    super.onInit();
  }

  @override
  void onReady() {
    
    super.onReady();
  }

  @override
  void onClose() {}
}
